package com.qc.ayouth.shop.dbs.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qc.ayouth.shop.dbs.constants.DbConstants;
import com.qc.ayouth.shop.dbs.entity.TSystemMenu;
import com.qc.ayouth.shop.dbs.mapper.TSystemMenuMapper;
import com.qc.ayouth.shop.dbs.service.system.TSystemMenuService;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 系统后台菜单  服务实现类
 * </p>
 *
 * @author Haojg
 * @since 2020-07-04
 */
@Service
public class TSystemMenuServiceImpl extends ServiceImpl<TSystemMenuMapper, TSystemMenu> implements TSystemMenuService {
    @Override
    public Set<String> getPermissionsSetByRoleIds(String roleIds) {
        Set<String> permissionsSet = new HashSet<String>();
        List<TSystemMenu> menuList = this.baseMapper.getMenuListByRoleIds(roleIds);
        for(TSystemMenu menu : menuList){
            permissionsSet.add(menu.getPermission());
        }
        return permissionsSet;
    }

    @Override
    public List<TSystemMenu> getMenuListByRoleIds(String roleIds) {
        return this.baseMapper.getMenuListByRoleIds(roleIds);
    }

    @Override
    public List<TSystemMenu> getActionListByMenuId(Long menuId) {
        QueryWrapper<TSystemMenu> qw = new QueryWrapper<>();
        qw.eq("is_deleted", 0);
        qw.eq("menu_type", DbConstants.MENU_TYPE_BUTTON);
        qw.eq("parent_id", menuId);
        return this.baseMapper.selectList(qw);
    }
}
